<?php

namespace app\pilot\model;

use app\task\model\OrderModel;
use think\admin\Model;

/**
 * 飞手余额记录模型
 * @class BalanceRecordModel
 * @package app\pilot\model
 */
class BalanceRecordModel extends Model
{
    protected $name = 'pilot_balance_record';

    /**
     * 字典-类型类型
     */
    public const TYPE__IN_TASK_PAYMENT = 1;
    public const TYPE__IN_WITHDRAW_BACK = 2;
    public const TYPE__OUT_WITHDRAW = -1;
    public const TYPE_DICT = [
        self::TYPE__IN_TASK_PAYMENT => '订单任务报酬',
        self::TYPE__IN_WITHDRAW_BACK => '余额提现恢复',
        self::TYPE__OUT_WITHDRAW => '余额提现',
    ];

    /**
     * 类型获取器
     * @param $value
     * @param $data
     * @return string
     */
    public function getTypeTextAttr($value, $data)
    {
        return self::TYPE_DICT[$data['type']] ?? '';
    }

    /**
     * 关联飞手
     */
    public function pilot(){
        return $this->belongsTo(PilotModel::class, 'pilot_id', 'id');
    }

    /**
     * 关联执行订单
     */
    public function taskOrder(){
        return $this->hasOne(OrderModel::class, 'id', 'task_order_id');
    }
}
